-- Snow

if minetest.setting_getbool("lunoweather_snow")~= false then
	minetest.setting_set("lunoweather_snow", "true")
end

if minetest.setting_getbool("lunoweather_snowmap")~= false then
	minetest.setting_set("lunoweather_snowmap", "true")
end

--#################################################################################################################

--[[
--Faz o Jogador não pode andar sobre a camada de neve fina!!!! (Isso desativa a neve quando o player esta sobre ela.)
local idSnow = "default:snow"
local props = minetest.registered_items[idSnow]
props.walkable = false
minetest.register_node(":"..idSnow, props)
]]--

--#################################################################################################################

minetest.register_globalstep(function(dtime)
	if minetest.setting_getbool("lunoweather_snow")== true then
		local players = minetest.get_connected_players()
		for _, player in ipairs(players) do
			local ppos = player:getpos()
			local myWeather = lunoweather.get_weather(ppos)
			if myWeather=="snow" then
				local minp = lunoweather.addvectors(ppos, {x=-9, y=7, z=-9})
				local maxp = lunoweather.addvectors(ppos, {x= 9, y=7, z= 9})

				local minp_deep = lunoweather.addvectors(ppos, {x=-10, y=3.2, z=-10})
				local maxp_deep = lunoweather.addvectors(ppos, {x= 10, y=2.6, z= 10})

				local vel = {x=0, y=   -0.5, z=0}
				local acc = {x=0, y=   -0.5, z=0}
			
				local luz = minetest.env:get_node_light(maxp, 0.5)
				if luz~=nil and luz>= 15 then
					minetest.add_particlespawner({
						--amount = 5,
						amount = math.ceil(5/#players),--math.ceil(arredonda para cima de 0.5), math.floor(arredonda para menor de 0.5)
						time = 0.5,
						minpos = minp,
						maxpos = maxp,
						minvel = vel,
						maxvel = vel,
						minacc = acc,
						maxacc = acc,
						minexptime = 5,
						maxexptime = 5,
						minsize = 25,
						maxsize = 25,
						collisiondetection = false,
						vertical = true, --Forca aparticula a fica sempre na vertical
						texture = "weather_snow.png",
						playername = player:get_player_name()
					})
				end
			end
		end
	end
end)

--#################################################################################################################


